package Basic.day04;

import java.util.Scanner;

public class MiddleSearch {
    public static void main(String[] args) {
        int arr[] = {1, 3, 5, 7, 8, 9, 10, 11, 12, 14, 15};
        int low = 0;
        int high = arr.length - 1;
        int mid = (low + high) / 2;
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要查找的数字");
        int num = sc.nextInt();
        for (int i = 0; i < arr.length; i++) {
            if (num > arr[mid] && low < high) {
                low = mid + 1;
                mid = (low + high) / 2;
            } else if (num < arr[mid] && low < high) {
                high = mid - 1;
                mid = (low + high) / 2;
            } else if (num == arr[mid]) {
                System.out.println("找到了，下标为" + mid);
                break;
            } else {
                System.out.println("数据集中没有匹配的数据");
                break;
            }

        }
        System.out.println("数据集中没有匹配的数据");
    }
}
